home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / rtfuncs.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-02  |  21.1 KB  |  983 lines

  1. ********************
  2. * ReqTools library *
  3. ********************
  4.  
  5.     SECTION "text",CODE
  6.  
  7.     INCLUDE    "exec/types.i"
  8.     INCLUDE    "exec/funcdef.i"
  9.     INCLUDE    "lvo/exec_lib.i"
  10.     INCLUDE    "exec/nodes.i"
  11.     INCLUDE    "exec/lists.i"
  12.     INCLUDE    "exec/alerts.i"
  13.     INCLUDE    "exec/libraries.i"
  14.     INCLUDE    "exec/memory.i"
  15.     INCLUDE    "dos/dos.i"
  16.     INCLUDE    "lvo/dos_lib.i"
  17.     INCLUDE    "dos/var.i"
  18.     INCLUDE    "graphics/gfxbase.i"
  19.     INCLUDE    "intuition/intuition.i"
  20.     INCLUDE    "intuition/classes.i"
  21.     INCLUDE    "intuition/classusr.i"
  22.     INCLUDE    "intuition/screens.i"
  23.     INCLUDE    "lvo/intuition_lib.i"
  24.     INCLUDE    "utility/hooks.i"
  25.  
  26.     INCLUDE    "libraries/reqtools.i"
  27.     INCLUDE    "lvo/reqtools_lib.i"
  28.  
  29.     INCLUDE    "boopsigads.i"
  30.  
  31.     XREF _myBoopsiDispatch
  32.     XREF _FreeReqToolsFonts
  33.     XREF DataTable
  34.     XREF __BSSLEN
  35.  
  36.     XDEF Init
  37.  
  38. Init:
  39.     dc.l    ReqToolsBase_SIZE
  40.     dc.l    FuncTable
  41.     dc.l    DataTable
  42.     dc.l    InitRoutine
  43.  
  44. dosName:
  45.     dc.b "dos.library",0
  46. intName:
  47.     dc.b "intuition.library",0
  48. gfxName:
  49.     dc.b "graphics.library",0
  50. gadName:
  51.     dc.b "gadtools.library",0
  52. utilName:
  53.     dc.b "utility.library",0
  54. layersName:
  55.     dc.b "layers.library",0
  56. localeName:
  57.     dc.b "locale.library",0
  58. consoleName:
  59.     dc.b "console.device",0
  60. imageclass:
  61.     dc.b "imageclass",0
  62. varname:
  63.     dc.b "ReqTools.prefs",0
  64.     ds.l    0
  65. ;    dc.l __BSSLEN            ; we need this line for Blink to generate BSS!
  66.  
  67.     EVEN
  68.  
  69. *****************************************************************************
  70.  
  71. ; D1 must hold default size, A1 is advanced, D1 is preserved
  72. InitReqDefaults:
  73.     move.l    d1,(a0)+        ; rtrd_Size
  74.     moveq    #REQPOS_TOPLEFTSCR,d0
  75.     move.l    d0,(a0)+        ; rtrd_ReqPos
  76. InitReqDefs_NoSizeNoReqPos:
  77.     moveq    #25,d0
  78.     move.w    d0,(a0)+        ; rtrd_LeftOffset
  79.     moveq    #18,d0
  80.     move.w    d0,(a0)+        ; rtrd_TopOffset
  81.     moveq    #6,d0
  82.     move.w    d0,(a0)+        ; rtrd_MinEntries
  83.     moveq    #10,d0
  84.     move.w    d0,(a0)+        ; rtrd_MaxEntries
  85.     rts
  86.  
  87.     ; Initialize library
  88.     ; d0 = library pointer, a0 = seglist, a6 = sysbase
  89.     ; -> d0 = non zero if lib must be linked in the system list
  90. InitRoutine:
  91.     movem.l    d2/a2/a4-a6,-(a7)    ; MUST BE SAME AS EXPUNGELIB !!!!!
  92.     move.l    d0,a5
  93.     lea    _ReqToolsBase,a4
  94.     move.l    d0,(a4)            ; our base to be used in C routines
  95.     move.l    a6,_SysBase-_ReqToolsBase(a4)
  96.     move.l    a0,rt_SegList(a5)
  97.  
  98.     move.w    #ReqToolsBase_SIZE,d0    ; set everything private to 0
  99.     sub.w    #rt_RealOpenCnt+1,d0
  100.     lea    rt_RealOpenCnt(a5),a0
  101. clear:
  102.     clr.b    (a0)+
  103.     dbf    d0,clear
  104.  
  105.     ; Fill in preference size
  106.     move.l    #RTPREFS_SIZE,rt_ReqToolsPrefs+rtpr_PrefsSize(a5)
  107.  
  108.     ; Initialize prefs semaphore
  109.     lea    rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a5),a0
  110.     jsr    _LVOInitSemaphore(a6)
  111.  
  112.     ; Set default preferences
  113.     lea    rt_ReqToolsPrefs+rtpr_ReqDefaults(a5),a0
  114.     moveq    #75,d1
  115.     bsr.b    InitReqDefaults        ; RTPREF_FILEREQ
  116.     move.w    #10,-4(a0)        ; set min entries to 10
  117.     move.w    #50,-2(a0)        ; set max entries to 50
  118.     moveq    #65,d1
  119.     bsr.b    InitReqDefaults        ; RTPREF_FONTREQ
  120.     bsr.b    InitReqDefaults        ; RTPREF_PALETTEREQ, size ignored
  121.     bsr.b    InitReqDefaults        ; RTPREF_SCREENMODEREQ
  122.     bsr.b    InitReqDefaults        ; RTPREF_VOLUMEREQ
  123.     addq.l    #8,a0
  124.     bsr.b    InitReqDefs_NoSizeNoReqPos ; RTPREF_OTHERREQ
  125.  
  126.     lea    intName(PC),a1
  127.     jsr    _LVOOldOpenLibrary(a6)
  128.     move.l    d0,_IntuitionBase-_ReqToolsBase(a4)
  129.     move.l    d0,rt_IntuitionBase(a5)
  130.     move.l    d0,d2
  131.  
  132.     move.l    d0,a0
  133.     moveq    #36,d0
  134.     cmp.w    LIB_VERSION(a0),d0    ; is version >= 37
  135.     bcs.b    okkick37
  136.  
  137.     lea    kickalertstr(PC),a0
  138.     move.l    d2,a6
  139.     moveq    #0,d0
  140.     moveq    #19,d1
  141.     jsr    _LVODisplayAlert(a6)
  142.     moveq    #0,d2
  143.     bra    errorinitlib
  144.  
  145. okkick37:
  146.     move.l    a0,a6
  147.     lea    imageclass(PC),a1
  148.     sub.l    a0,a0
  149.     sub.l    a2,a2
  150.     moveq    #lod_SIZEOF,d0
  151.     moveq    #0,d1
  152.     jsr    _LVOMakeClass(a6)
  153.     moveq    #0,d2
  154.     move.l    d0,_ButtonImgClass-_ReqToolsBase(a4)
  155.     beq    errorinitlib        ; A6 MUST hold IntuitionBase!
  156.  
  157.     move.l    d0,a1
  158.     move.l    #_myBoopsiDispatch,cl_Dispatcher+h_Entry(a1)
  159.     move.l    $4.w,a6
  160.  
  161.     lea    gadName(PC),a1
  162.     jsr    _LVOOldOpenLibrary(a6)
  163.     move.l    d0,_GadToolsBase-_ReqToolsBase(a4)
  164.     move.l    d0,rt_GadToolsBase(a5)
  165.  
  166.     lea    dosName(PC),a1
  167.     jsr    _LVOOldOpenLibrary(a6)
  168.     move.l    d0,_DOSBase-_ReqToolsBase(a4)
  169.     move.l    d0,rt_DOSBase(a5)
  170.  
  171.     ; Get current ReqTools preferences (D0 = DOSBase)
  172.     movem.l    d2-d4/a6,-(a7)
  173.     move.l    d0,a6
  174.     lea    varname(PC),a0
  175.     move.l    a0,d1
  176.     lea    rt_ReqToolsPrefs+rtpr_Flags(a5),a0
  177.     move.l    a0,d2
  178.     move.l    rt_ReqToolsPrefs+rtpr_PrefsSize(a5),d3
  179.     move.l    #GVF_BINARY_VAR!GVF_GLOBAL_ONLY!LV_VAR,d4
  180.     jsr    _LVOGetVar(a6)
  181.     movem.l    (a7)+,d2-d4/a6
  182.  
  183.     lea    gfxName(PC),a1
  184.     jsr    _LVOOldOpenLibrary(a6)
  185.     move.l    d0,_GfxBase-_ReqToolsBase(a4)
  186.     move.l    d0,rt_GfxBase(a5)
  187.     move.l    d0,a0
  188.  
  189.     lea    utilName(PC),a1
  190.     jsr    _LVOOldOpenLibrary(a6)
  191.     move.l    d0,_UtilityBase-_ReqToolsBase(a4)
  192.     move.l    d0,rt_UtilityBase(a5)
  193.  
  194.     lea    layersName(PC),a1
  195.     jsr    _LVOOldOpenLibrary(a6)
  196.     move.l    d0,_LayersBase-_ReqToolsBase(a4)
  197.  
  198.     lea    localeName(PC),a1
  199.     jsr    _LVOOldOpenLibrary(a6)
  200.     move.l    d0,_LocaleBase-_ReqToolsBase(a4)
  201.  
  202.     lea    consoleName(PC),a0
  203.     lea    iorequest-_ReqToolsBase(a4),a1
  204.     moveq    #-1,d0
  205.     moveq    #0,d1
  206.     jsr    _LVOOpenDevice(a6)
  207.     move.l    iorequest-_ReqToolsBase+IO_DEVICE(a4),d0
  208.     move.l    d0,_ConsoleDevice-_ReqToolsBase(a4)
  209.  
  210.     move.l    a5,d0
  211.     movem.l    (a7)+,d2/a2/a4-a6
  212.     rts
  213.  
  214. kickalertstr:
  215.     dc.b 0,96,11
  216.     dc.b "This version of reqtools.library needs Kickstart 2.0 V37+",0,0
  217.  
  218.     cnop 0,2
  219.  
  220.     ; Open library
  221.     ; d0 = version, a6 = ptr to lib
  222.     ; -> d0 = ptr to lib
  223. Open:
  224. ;    addq.w    #1,LIB_OPENCNT(a6)
  225.     addq.w    #1,rt_RealOpenCnt(a6)
  226. ;    bclr.b    #LIBB_DELEXP,rt_RTFlags(a6)    ; Prevent delayed expunges
  227.     move.l    a6,d0
  228.     rts
  229.  
  230.     ; Close library
  231.     ; a6 = ptr to lib
  232.     ; -> d0 = return seglist if lib is completely closed and delayed expunge
  233. Close:
  234.     moveq    #0,d0
  235. ;    subq.w    #1,LIB_OPENCNT(a6)
  236.     subq.w    #1,rt_RealOpenCnt(a6)
  237. ;    bne.s    EndClose
  238.  
  239. ;    btst    #LIBB_DELEXP,rt_RTFlags(a6)
  240. ;    bne.s    Expunge
  241. EndClose:
  242.     rts
  243.  
  244.     ; Expunge the library
  245.     ; a6 = ptr to lib
  246.     ; -> d0 = seglist if library is no longer open
  247. Expunge:
  248.     movem.l    d2/a2/a4-a6,-(a7)    ; MUST BE SAME AS INITLIB !!!!!
  249.     move.l    a6,a5
  250.     move.l    $4.w,a6
  251.  
  252.     tst.w    rt_AvailFontsLock(a5)
  253.     bne.b    noavailfonts
  254.  
  255.     jsr    _FreeReqToolsFonts(PC)
  256. noavailfonts:
  257.  
  258. ;    tst.w    LIB_OPENCNT(a5)
  259.     tst.w    rt_RealOpenCnt(a5)
  260.     beq.b    NoOneOpen
  261.  
  262. ;    bset.b    #LIBB_DELEXP,rt_RTFlags(a5) ; still open, set delayed expunge flag
  263.     moveq    #0,d0
  264.     bra.b    ExpungeEnd
  265.  
  266. NoOneOpen:
  267.     move.l    rt_SegList(a5),d2
  268.     move.l    a5,a1
  269.     jsr    _LVORemove(a6)        ; remove lib
  270.     lea    iorequest,a1
  271.     jsr    _LVOCloseDevice(a6)    ; close console.device
  272.     move.l    rt_DOSBase(a5),a1
  273.     jsr    _LVOCloseLibrary(a6)    ; close DOS
  274.     move.l    rt_GadToolsBase(a5),a1
  275.     jsr    _LVOCloseLibrary(a6)    ; close GadTools
  276.     move.l    rt_GfxBase(a5),a1
  277.     jsr    _LVOCloseLibrary(a6)    ; close Gfx
  278.     move.l    rt_UtilityBase(a5),a1
  279.     jsr    _LVOCloseLibrary(a6)    ; close Utility
  280.     move.l    _LayersBase,a1
  281.     jsr    _LVOCloseLibrary(a6)
  282.     move.l    _LocaleBase,a1
  283.     jsr    _LVOCloseLibrary(a6)
  284.     move.l    rt_IntuitionBase(a5),a6
  285.     move.l    _ButtonImgClass,a0
  286.     jsr    _LVOFreeClass(a6)    ; free image class
  287. errorinitlib:
  288.     move.l    a6,a1
  289.     move.l    ($4).w,a6
  290.     jsr    _LVOCloseLibrary(a6)    ; close Intuition
  291.  
  292.     move.l    a5,a1
  293.     moveq    #0,d0
  294.     move.w    LIB_NEGSIZE(a5),d0
  295.     sub.l    d0,a1
  296.     add.w    LIB_POSSIZE(a5),d0
  297.     jsr    _LVOFreeMem(a6)        ; free our mem
  298.     move.l    d2,d0            ; seglist
  299. ExpungeEnd:
  300.     movem.l    (a7)+,d2/a2/a4-a6
  301.     rts
  302.  
  303.     ; Do nothing function
  304. Null:
  305.     moveq        #0,d0
  306.     rts
  307.  
  308. ******************************************************************************
  309. *
  310. * ReqTools Functions
  311. *
  312. ******************************************************************************
  313.  
  314.     XREF _AllocRequestA
  315.     XREF _FreeRequest
  316.     XREF _FreeReqBuffer
  317.     XREF _FileRequestA
  318.     XREF _ChangeReqAttrA
  319.     XREF _FreeFileList
  320.     XREF _PaletteRequestA
  321.     XREF _GetVScreenSize
  322.     XREF _CloseWindowSafely
  323.  
  324. FuncTable:
  325.     dc.l Open
  326.     dc.l Close
  327.     dc.l Expunge
  328.     dc.l Null
  329.  
  330.     dc.l _AllocRequestA
  331.     dc.l _FreeRequest
  332.     dc.l _FreeReqBuffer
  333.     dc.l _ChangeReqAttrA
  334.     dc.l _FileRequestA
  335.     dc.l _FreeFileList
  336.     dc.l rtEZRequestA
  337.     dc.l rtGetStringA
  338.     dc.l rtGetLongA
  339.     dc.l rtInternalGetPasswordA    ; private
  340.     dc.l rtInternalEnterPasswordA    ; private
  341.     dc.l _FileRequestA         ; = _FontRequestA!
  342.     dc.l _PaletteRequestA
  343.     dc.l rtReqHandlerA
  344.     dc.l rtSetWaitPointer
  345.     dc.l _GetVScreenSize
  346.     dc.l rtSetReqPosition
  347.     dc.l rtSpread
  348.     dc.l rtScreenToFrontSafely
  349.     dc.l _FileRequestA        ; rtScreenModeRequestA
  350.     dc.l _CloseWindowSafely
  351.     dc.l rtLockWindow
  352.     dc.l rtUnLockWindow
  353.     ; private funcs for preferences
  354.     dc.l rtLockPrefs
  355.     dc.l rtUnlockPrefs
  356.     dc.l -1
  357.  
  358. *----------------------------------------------------------------------------*
  359. * -- PRIVATE --
  360. * struct ReqToolsPrefs *rtLockPrefs (void);
  361. * d0
  362.  
  363. rtLockPrefs:
  364.     move.l    a6,-(a7)
  365.     lea    rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a6),a0
  366.     move.l    $4.w,a6
  367.     jsr    _LVOObtainSemaphore(a6)
  368.     move.l    (a7)+,a6
  369.     lea    rt_ReqToolsPrefs(a6),a0
  370.     move.l    a0,d0
  371.     rts
  372.  
  373. *----------------------------------------------------------------------------*
  374. * -- PRIVATE --
  375. * void rtUnlockPrefs (void);
  376.  
  377. rtUnlockPrefs:
  378.     move.l    a6,-(a7)
  379.     lea    rt_ReqToolsPrefs+rtpr_PrefsSemaphore(a6),a0
  380.     move.l    $4.w,a6
  381.     jsr    _LVOReleaseSemaphore(a6)
  382.     move.l    (a7)+,a6
  383.     rts
  384.  
  385.     XREF _GetString
  386.  
  387. CHECK_PASSWORD    equ    0
  388. ENTER_PASSWORD    equ    1
  389. ENTER_STRING    equ    2
  390. ENTER_NUMBER    equ    3
  391. IS_EZREQUEST    equ    4
  392.  
  393. *----------------------------------------------------------------------------*
  394. * -- PRIVATE --
  395. * BOOL rtInternalEnterPasswordA (UBYTE *, char *(*)(), struct TagItem *);
  396. * d0                             a1       d2           a0
  397.  
  398. rtInternalEnterPasswordA:
  399.     movem.l    d2-d4/a2,-(a7)
  400.     moveq    #ENTER_PASSWORD,d3
  401.     bra.b    getpass
  402.  
  403. *----------------------------------------------------------------------------*
  404. * -- PRIVATE --
  405. * BOOL rtInternalGetPasswordA (UBYTE *, ULONG, char *(*)(), struct TagItem *);
  406. * d0                           a1       d1:16  d2           a0
  407.  
  408. rtInternalGetPasswordA:
  409.     movem.l    d2-d4/a2,-(a7)
  410.     moveq    #CHECK_PASSWORD,d3
  411.     clr.b    (a1)
  412. getpass:
  413.     moveq    #16,d0
  414.     lea    PwTitle(PC),a2
  415.     andi.l    #$ffff,d1
  416.     bra.b    GetStr_PopD2toD4_A2_RTS
  417.  
  418. PwTitle:
  419.     dc.b "Password",0
  420.     cnop 0,2
  421.  
  422. *----------------------------------------------------------------------------*
  423. * BOOL rtGetStringA
  424. *              (UBYTE *, ULONG, char *, struct rtReqInfo *, struct TagItem *);
  425. * d0            a1       d0     a2      a3                  a0
  426.  
  427.     XREF    _CheckStackCallFunc
  428.  
  429. rtGetStringA:
  430.     movem.l    d2-d4/a2,-(a7)
  431.     moveq    #ENTER_STRING,d3
  432. GetStr_PopD2toD4_A2_RTS:
  433.     move.l    a3,d4
  434.  
  435.     pea    _GetString(PC)
  436.     jsr    _CheckStackCallFunc(PC)
  437.  
  438.     movem.l    (a7)+,d2-d4/a2
  439.     rts
  440.  
  441. *----------------------------------------------------------------------------*
  442. * ULONG rtEZRequestA
  443. *                (char *, char *, struct rtReqInfo *, APTR, struct TagItem *);
  444. * d0              a1      a2      a3                  a4    a0
  445.  
  446. rtEZRequestA:
  447.     movem.l    d2-d4/a2,-(a7)
  448.     move.l    a4,d0            ; args
  449.     moveq    #IS_EZREQUEST,d3
  450.     bra.b    GetStr_PopD2toD4_A2_RTS
  451.  
  452. *----------------------------------------------------------------------------*
  453. * BOOL rtGetLongA (ULONG *, char *, struct rtReqInfo *, struct TagItem *);
  454. * d0               a1       a2      a3                  a0
  455.  
  456. rtGetLongA:
  457.     movem.l    d2-d4/a2,-(a7)
  458.     move.l    a1,d2
  459.     moveq    #ENTER_NUMBER,d3
  460.     bra.b    GetStr_PopD2toD4_A2_RTS
  461.  
  462. *----------------------------------------------------------------------------*
  463. * ULONG rtReqHandlerA (APTR, ULONG *, struct TagItem *);
  464. * d0                   a1    a2       a0
  465.  
  466.     XDEF    rtReqHandlerA
  467.  
  468. rtReqHandlerA:
  469.     move.l    (a1),-(a7)                ; first longword holds real function address!
  470.     rts
  471.  
  472. *----------------------------------------------------------------------------*
  473. * void rtSetWaitPointer (struct Window *);
  474. *                        a0
  475.  
  476.     XREF        _waitpointer
  477.  
  478. rtSetWaitPointer:
  479.     movem.l    d2/d3/a6,-(a7)
  480.     move.l    $4.w,a1
  481.     moveq        #38,d0
  482.     cmp.w        LIB_VERSION(a1),d0            ; is version >= 39
  483.     bcs.b        .iskick39
  484.     lea        _waitpointer,a1
  485.     moveq        #16,d0
  486.     moveq        #16,d1
  487.     moveq        #-6,d2
  488.     moveq        #0,d3
  489.     move.l    rt_IntuitionBase(a6),a6
  490.     jsr        _LVOSetPointer(a6)
  491.     bra.b        .endsetwaitpointer
  492. .iskick39:
  493.     lea        setpointertaglist(PC),a1
  494.     move.l    rt_IntuitionBase(a6),a6
  495.     jsr        _LVOSetWindowPointerA(a6)
  496. .endsetwaitpointer:
  497.     movem.l    (a7)+,d2/d3/a6
  498.     rts
  499.  
  500. setpointertaglist:
  501.     dc.l WA_BusyPointer,1,TAG_DONE
  502.  
  503. *----------------------------------------------------------------------------*
  504. * APTR rtLockWindow (struct Window *);
  505. *                    a0
  506.  
  507.     STRUCTURE    rtWindowLock,0
  508.     * requester structure (MUST BE FIRST ITEM!!!)
  509.     STRUCT    rtwl_Requester,rq_SIZEOF
  510.     APTR    rtwl_Magic
  511.     ULONG    rtwl_RequesterPtr
  512.     ULONG    rtwl_LockCount
  513.     ULONG    rtwl_ReqInstalled
  514.     * same as in Window structure (same order as well!)
  515.     APTR    rtwl_Pointer
  516.     BYTE    rtwl_PtrHeight
  517.     BYTE    rtwl_PtrWidth
  518.     BYTE    rtwl_XOffset
  519.     BYTE    rtwl_YOffset
  520.     WORD    rtwl_MinWidth
  521.     WORD    rtwl_MinHeight
  522.     WORD    rtwl_MaxWidth
  523.     WORD    rtwl_MaxHeight
  524.     LABEL    rtwl_SIZEOF
  525.  
  526. LOCKWINMAGIC        equ        'rtLW'
  527.  
  528. rtLockWindow:
  529.     movem.l    d2/d3/a0/a2/a6,-(a7)    ; DON'T CHANGE THIS WITHOUT THINKING!!
  530.  
  531.     * First see if we already locked this window.
  532.     move.l    wd_FirstRequest(a0),a1
  533. .nextreq:
  534.     move.l    a1,d0
  535.     beq.b    .noreq
  536.  
  537.     move.l    rtwl_Magic(a1),d0
  538.     cmp.l    #LOCKWINMAGIC,d0
  539.     bne.b    .nomagic
  540.  
  541.     cmp.l    rtwl_RequesterPtr(a1),a1
  542.     beq.b    .increasecount
  543.  
  544. .nomagic:
  545.     move.l    (a1),a1
  546.     bra.b    .nextreq
  547.  
  548.     * If the window was already locked increase lock-count
  549.  
  550. .increasecount:
  551.     addq.l    #1,rtwl_LockCount(a1)
  552.     move.l    a1,d0            ; return window lock
  553.     bra    endlockwin
  554.  
  555.     * Lock the window
  556. .noreq:
  557.     move.l    #rtwl_SIZEOF,d0
  558.     move.l    #MEMF_CLEAR,d1
  559.     move.l    a6,-(a7)
  560.     move.l    $4.w,a6
  561.     jsr    _LVOAllocVec(a6)
  562.     move.l    (a7)+,a6
  563.     tst.l    d0
  564.     beq.b    endlockwin
  565.  
  566.     move.l    d0,a2
  567.     move.l    d0,rtwl_RequesterPtr(a2)
  568.     move.l    #LOCKWINMAGIC,rtwl_Magic(a2)
  569.  
  570.     move.l    rt_IntuitionBase(a6),a6
  571.  
  572.     move.l    8(a7),a0        ; A0 on stack + 8 = window ptr
  573.     lea    rtwl_MinWidth(a2),a1
  574.     move.l    wd_MinWidth(a0),(a1)+    ; remember wd_MinWidth and wd_MinHeight
  575.     move.l    wd_MaxWidth(a0),(a1)+    ; remember wd_MaxWidth and wd_MaxHeight
  576.     moveq    #0,d0
  577.     move.w    wd_Width(a0),d0
  578.     moveq    #0,d1
  579.     move.w    wd_Height(a0),d1
  580.     move.l    d0,d2
  581.     move.l    d1,d3
  582.     jsr    _LVOWindowLimits(a6)    ; set window limits to current size
  583.  
  584.     move.l    a2,a0
  585.     jsr    _LVOInitRequester(a6)
  586.  
  587.     move.l    8(a7),a1        ; A0 on stack + 8 = window ptr
  588.     move.l    a2,a0
  589.     jsr    _LVORequest(a6)
  590.     move.l    d0,rtwl_ReqInstalled(a2)
  591.  
  592.     move.l    8(a7),a0
  593.     move.l    16(a7),a6
  594.     lea    rtwl_Pointer(a2),a1
  595.     move.l    wd_Pointer(a0),(a1)+    ; remember wd_Pointer
  596.     move.l    wd_PtrHeight(a0),(a1)+    ; remember wd_PtrHeight, wd_PtrWidth,...
  597.     jsr    _LVOrtSetWaitPointer(a6)
  598.  
  599.     move.l    a2,d0
  600. endlockwin:
  601.     movem.l    (a7)+,d2/d3/a0/a2/a6
  602.     rts
  603.  
  604. *----------------------------------------------------------------------------*
  605. * ULONG rtUnLockWindow (struct Window *, APTR lock);
  606. *                       a0               a1
  607.  
  608. rtUnLockWindow:
  609.     movem.l    d2/d3/a0/a1/a6,-(a7)
  610.     move.l    a1,d0
  611.     beq    endunlockwin
  612.  
  613.     move.l    rtwl_LockCount(a1),d0
  614.     beq.b    .unlockwin
  615.  
  616.     subq.l    #1,rtwl_LockCount(a1)
  617.     bra.b    endunlockwin
  618.  
  619. .unlockwin:
  620.     * restore old window pointer
  621.     move.l    rt_IntuitionBase(a6),a6
  622.     tst.l    rtwl_Pointer(a1)
  623.     beq.b    .clrptr
  624.  
  625.     moveq    #0,d0
  626.     move.b    rtwl_PtrHeight(a1),d0
  627.     moveq    #0,d1
  628.     move.b    rtwl_PtrWidth(a1),d1
  629.     move.b    rtwl_XOffset(a1),d2
  630.     ext.w    d2
  631.     ext.l    d2
  632.     move.b    rtwl_YOffset(a1),d3
  633.     ext.w    d3
  634.     ext.l    d3
  635.     move.l    rtwl_Pointer(a1),a1
  636.     jsr    _LVOSetPointer(a6)
  637.     bra.b    endreq
  638. .clrptr:
  639.     jsr    _LVOClearPointer(a6)
  640.  
  641. endreq:
  642.     movem.l    8(a7),a0/a1
  643.     tst.l    rtwl_ReqInstalled(a1)
  644.     beq.b    noreqinstalled
  645.  
  646.     exg.l    a0,a1
  647.     jsr    _LVOEndRequest(a6)
  648.     movem.l    8(a7),a0/a1
  649. noreqinstalled:
  650.  
  651.     * restore wd_MinWidth, wd_MinHeight, wd_MaxWidth and wd_MaxHeight
  652.     moveq    #0,d0
  653.     move.w    rtwl_MinWidth(a1),d0
  654.     moveq    #0,d1
  655.     move.w    rtwl_MinHeight(a1),d1
  656.     moveq    #0,d2
  657.     move.w    rtwl_MaxWidth(a1),d2
  658.     moveq    #0,d3
  659.     move.w    rtwl_MaxHeight(a1),d3
  660.     jsr    _LVOWindowLimits(a6)    ; reset window limits
  661.     movem.l    8(a7),a0/a1
  662.  
  663.     * free lock
  664.     move.l    $4.w,a6
  665.     jsr    _LVOFreeVec(a6)
  666.  
  667. endunlockwin:
  668.     movem.l    (a7)+,d2/d3/a0/a1/a6
  669.     rts
  670.  
  671. *----------------------------------------------------------------------------*
  672. * void rtSpread (ULONG *, ULONG *, ULONG,  ULONG, ULONG, ULONG);
  673. *               (pos,     width,   length, x1,    x2,    num);
  674. * D0             A0       A1       D0      D1     D2     D3
  675.  
  676. rtSpread:
  677.     movem.l    d2/d3/d4/d5,-(a7)
  678.     move.l    d1,d5
  679.     swap    d5
  680.     clr.w    d5            ; gadpos (D5) = x1 << 16
  681.     move.l    d3,d4            ; num-- (D4)
  682.     subq.l    #1,d4
  683.     move.l    d2,d3
  684.     sub.l    d1,d3
  685.     sub.l    d0,d3
  686.     divs    d4,d3
  687.     swap    d3
  688.     clr.w    d3            ; gadgap (D3) = ((x2-x1-totwidth) / num) << 16
  689.     moveq    #0,d0            ; i (D0) = 0
  690. loopspread:
  691.     cmp.w    d0,d4
  692.     bcs.s    endspread
  693.     bne.s    notnum
  694.  
  695.     move.l    d2,d1            ; pos[i] = x2 - width[i]
  696.     sub.l    (a1),d1
  697.     bra.b    addpos
  698. notnum:
  699.     move.l    d5,d1            ; pos[i] = gadpos >> 16
  700.     clr.w    d1
  701.     swap    d1
  702. addpos:
  703.     move.l    d1,(a0)+
  704.     move.l    (a1)+,d1        ; gadpos += (width[i] << 16) + gadgap
  705.     swap    d1
  706.     clr.w    d1
  707.     add.l    d3,d1
  708.     add.l    d1,d5
  709.     addq.l    #1,d0
  710.     bra.b    loopspread
  711.  
  712. endspread:
  713.     movem.l    (a7)+,d2/d3/d4/d5
  714.     rts
  715.  
  716. *----------------------------------------------------------------------------*
  717. * void rtScreenToFrontSafely (struct Screen *);
  718. *                             a0
  719.  
  720. rtScreenToFrontSafely:
  721.     move.l    a6,-(a7)
  722.     move.l    rt_IntuitionBase(a6),a1
  723.     move.l    ($4).w,a6
  724.     jsr    _LVOForbid(a6)        ; a1 will be preserved
  725.     move.l    a1,a6
  726.     move.l    ib_FirstScreen(a6),a1
  727. loopscr:
  728.     move.l    a1,d0
  729.     beq.b    nofoundscr
  730.  
  731.     cmp.l    a1,a0
  732.     beq.b    foundscr
  733.  
  734.     move.l    (a1),a1            ; == move.l sc_NextScreen(a1),a1
  735.     bra.b    loopscr
  736. foundscr:
  737.     jsr    _LVOScreenToFront(a6)
  738. nofoundscr:
  739.     move.l    ($4).w,a6
  740.     jsr    _LVOPermit(a6)
  741.     move.l    (a7)+,a6
  742.     rts
  743.  
  744. *----------------------------------------------------------------------------*
  745. * void rtSetReqPosition
  746. *               (ULONG, struct NewWindow *, struct Screen *, struct Window *);
  747. *                d0     a0                  a1               a2
  748.  
  749. ;void __asm SetReqPosition (
  750. ;    register __d0 int reqpos,
  751. ;    register __a0 struct NewWindow *nw,
  752. ;    register __a1 struct Screen *scr,
  753. ;    register __a2 struct Window *win)
  754. ;{
  755. ;    int mx, my, val, leftedge, topedge;
  756. ;    int scrwidth, scrheight;
  757. ;    int width, height, left, top;
  758. ;
  759. ;    rtGetVScreenSize (scr, &scrwidth, &scrheight);
  760. ;    leftedge = -scr->LeftEdge;
  761. ;    if (leftedge < 0) leftedge = 0;
  762. ;    topedge = -scr->TopEdge;
  763. ;    if (topedge < 0) topedge = 0;
  764. ;
  765. ;    left = leftedge; top = topedge;
  766. ;    width = scrwidth; height = scrheight;
  767. ;    switch (reqpos) {
  768. ;        case REQPOS_DEFAULT:
  769. ;            nw->LeftEdge = 25;
  770. ;            nw->TopEdge = 18;
  771. ;            goto topleftscr;
  772. ;        case REQPOS_POINTER:
  773. ;            mx = scr->MouseX; my = scr->MouseY;
  774. ;            break;
  775. ;        case REQPOS_CENTERWIN:
  776. ;            if (win) {
  777. ;                left = win->LeftEdge; top = win->TopEdge;
  778. ;                width = win->Width; height = win->Height;
  779. ;                }
  780. ;        case REQPOS_CENTERSCR:
  781. ;            mx = (width - nw->Width) / 2 + left;
  782. ;            my = (height - nw->Height) / 2 + top;
  783. ;            break;
  784. ;        case REQPOS_TOPLEFTWIN:
  785. ;            if (win) {
  786. ;                left = win->LeftEdge;
  787. ;                top = win->TopEdge;
  788. ;                }
  789. ;        case REQPOS_TOPLEFTSCR:
  790. ;topleftscr:
  791. ;            mx = left; my = top;
  792. ;            break;
  793. ;        }
  794. ;
  795. ;    /* keep window completely visible */
  796. ;    mx += nw->LeftEdge; my += nw->TopEdge;
  797. ;    val = leftedge + scrwidth - nw->Width;
  798. ;    if (mx < leftedge) mx = leftedge;
  799. ;    else if (mx > val) mx = val;
  800. ;    val = topedge + scrheight - nw->Height;
  801. ;    if (my < topedge) my = topedge;
  802. ;    else if (my > val) my = val;
  803. ;
  804. ;    nw->LeftEdge = mx; nw->TopEdge = my;
  805. ;}
  806.  
  807. REQPOS_DEFAULT        equ    $FFFF
  808.  
  809. rtSetReqPosition:
  810.     movem.l    d2-d7/a2-a5,-(a7)
  811.     move.l    a0,a4            ; a4 = newwindow
  812.     move.l    a1,a3            ; a3 = screen
  813.     move.l    a2,a5            ; a5 = win
  814.     move.l    a1,a0
  815.     subq.w    #4,a7
  816.     move.l    a7,a1
  817.     subq.w    #4,a7
  818.     move.l    a7,a2
  819.     move.l    d0,-(a7)
  820.     jsr    _LVOrtGetVScreenSize(a6)
  821.     move.l    (a7)+,d0
  822.     move.l    (a7)+,d7        ; d7 = scrheight
  823.     move.l    (a7)+,d6        ; d6 = scrwidth
  824.     moveq    #0,d1
  825.     move.w    sc_LeftEdge(a3),d1
  826.     ext.l    d1
  827.     neg.l    d1            ; d1 = leftedge
  828.     bpl.b    posleft
  829.  
  830.     moveq    #0,d1
  831. posleft:
  832.     moveq    #0,d2
  833.     move.w    sc_TopEdge(a3),d2
  834.     ext.l    d2
  835.     neg.l    d2            ; d2 = topedge
  836.     bpl.b    postop
  837.  
  838.     moveq    #0,d2
  839. postop:
  840.     move.l    d1,d3            ; d3 = left
  841.     move.l    d2,d4            ; d4 = top
  842.     move.l    d6,a1            ; a1 = width
  843.     move.l    d7,a2            ; a2 = height
  844.     ; switch (reqpos) {
  845.     cmp.l    #REQPOS_DEFAULT,d0    ; is d0 == REQPOS_DEFAULT
  846.     bne.b    notdefault
  847.  
  848.     ; case REQPOS_DEFAULT:
  849.     moveq    #25,d0
  850.     move.w    d0,(a4)            ; == move.w d5,nw_LeftEdge(a4)
  851.     moveq    #18,d0
  852.     move.w    d0,nw_TopEdge(a4)
  853.     bra.b    tlscr
  854.  
  855. notdefault:
  856.     tst.l    d0
  857.     bne.b    notpointer
  858.  
  859.     ; case REQPOS_POINTER:
  860.     move.w    sc_MouseX(a3),d3    ; mx = scr->MouseX
  861.     move.w    sc_MouseY(a3),d4    ; my = scr->MouseY
  862.     bra.b    endswitch
  863.  
  864. notpointer:
  865.     subq.l    #1,d0
  866.     bne.b    notcentwin
  867.  
  868.     ; case REQPOS_CENTERWIN:
  869.     move.l    a5,d0
  870.     beq.b    centscr
  871.  
  872.     move.w    wd_LeftEdge(a5),d3    ; left = win->LeftEdge
  873.     move.w    wd_TopEdge(a5),d4    ; top = win->TopEdge
  874.     move.w    wd_Width(a5),a1        ; width = win->Width
  875.     move.w    wd_Height(a5),a2    ; height = win->Height
  876.     bra.b    centscr
  877.  
  878. notcentwin:
  879.     subq.l    #1,d0
  880.     bne.b    notcentscr
  881.  
  882.     ; case REQPOS_CENTERSCR:
  883. centscr:
  884.     move.l    a1,d0
  885.     moveq    #0,d5
  886.     move.w    nw_Width(a4),d5
  887.     sub.l    d5,d0
  888.     lsr.l    #1,d0
  889.     add.l    d0,d3            ; mx = (width - nw->Width) / 2 + left
  890.     move.l    a2,d0
  891.     move.w    nw_Height(a4),d5
  892.     sub.l    d5,d0
  893.     lsr.l    #1,d0
  894.     add.l    d0,d4            ; my = (height - nw->Height) / 2 + top
  895.     bra.b    endswitch
  896.  
  897. notcentscr:
  898.     subq.l    #1,d0
  899.     bne.b    nottlwin
  900.  
  901.     ; case REQPOS_TOPLEFTWIN:
  902.     move.l    a5,d0
  903.     beq.b    tlscr
  904.  
  905.     move.w    wd_LeftEdge(a5),d3    ; left = win->LeftEdge
  906.     move.w    wd_TopEdge(a5),d4    ; top = win->TopEdge
  907. *    bra.b    tlscr
  908.  
  909. nottlwin:
  910. *    subq.l    #1,d0
  911. *    bne.b    endswitch
  912.  
  913.     ; case REQPOS_TOPLEFTSCR:
  914. tlscr:
  915. *    move.l    d3,d3            ; mx = left
  916. *    move.l    d4,d4            ; my = top
  917. endswitch:
  918.     ; } /* switch */
  919.  
  920.     add.w    (a4),d3            ; == add.w nw_LeftEdge(a4),d3
  921.     cmp.w    d1,d3
  922.     bgt.s    okleft
  923.  
  924.     move.w    d1,d3
  925. okleft:
  926.     add.w    d6,d1
  927.     sub.w    nw_Width(a4),d1        ; leftedge + scrwidth - nw->Width
  928.     cmp.w    d1,d3
  929.     blt.s    okright
  930.  
  931.     move.w    d1,d3
  932. okright:
  933.  
  934.     add.w    nw_TopEdge(a4),d4
  935.     cmp.w    d2,d4
  936.     bgt.s    oktop
  937.  
  938.     move.w    d2,d4
  939. oktop:
  940.     add.w    d7,d2
  941.     sub.w    nw_Height(a4),d2    ; leftedge + scrwidth - nw->Width
  942.     cmp.w    d2,d4
  943.     blt.s    okbottom
  944.  
  945.     move.w    d2,d4
  946. okbottom:
  947.  
  948.     move.w    d3,(a4)            ; == move.w d3,nw_LeftEdge(a4)
  949.     move.w    d4,nw_TopEdge(a4)
  950.  
  951.     movem.l    (a7)+,d2-d7/a2-a5
  952.     rts
  953.  
  954.  
  955.     SECTION __MERGED,BSS
  956.  
  957.     XDEF _ReqToolsBase
  958.     XDEF _IntuitionBase
  959.     XDEF _GadToolsBase
  960.     XDEF _DOSBase
  961.     XDEF _GfxBase
  962.     XDEF _UtilityBase
  963.     XDEF _LayersBase
  964.     XDEF _LocaleBase
  965.     XDEF _ConsoleDevice
  966.     XDEF _ButtonImgClass
  967.     XDEF _SysBase
  968.  
  969. _ReqToolsBase:        ds.b 4
  970. _SysBase:        ds.b 4
  971. _IntuitionBase:        ds.b 4
  972. _GadToolsBase:        ds.b 4
  973. _DOSBase:        ds.b 4
  974. _GfxBase:        ds.b 4
  975. _UtilityBase:        ds.b 4
  976. _LayersBase:        ds.b 4
  977. _LocaleBase:        ds.b 4
  978. _ConsoleDevice:        ds.b 4
  979. _ButtonImgClass:    ds.b 4
  980. iorequest:        ds.b IOSTD_SIZE
  981.  
  982.     END
  983.